package com.twu.biblioteca;

import java.util.List;

/**
 * Created by utsabban on 3/4/14.
 */
public class Librarian {
    private Library library;
    private String librarianPassword;

    public Librarian(Library library) {
        this.library = library;
        librarianPassword="libPass";
    }

    public boolean librarianLogin(String inputPassword)
    {
        if(inputPassword.equals(librarianPassword))
            return true;
        else
            return false;
    }

    public String displayBorrowersOfAParticularBookOrMovie(String queriedBookOrMovie)
    {
        List<Book> bookList=library.getBookList();
        List<Movie> movieList=library.getMovieList();
        String borrowersListString="";

        for(Book book:bookList)
        {
            if(book.getBookName().equals(queriedBookOrMovie))
            {
                borrowersListString+="Book : "+queriedBookOrMovie+"\nBorrowers : ";
                List<String> borrowersList=book.returnBorrowers();
                if (borrowersList.isEmpty())
                    borrowersListString+="No one has borrowed yet!";
                else
                {
                    for (String borrowerNumber:borrowersList)
                        borrowersListString+=borrowerNumber+" ";
                }
                borrowersListString+="\n";
                break;
            }
        }

        for(Movie movie:movieList)
        {
            if(movie.getMovieName().equals(queriedBookOrMovie))
            {
                borrowersListString+="Movie : "+queriedBookOrMovie+"\nBorrowers : ";
                List<String> borrowersList=movie.returnBorrowers();
                if (borrowersList.isEmpty())
                    borrowersListString+="No one has borrowed yet!";
                else
                {
                    for (String borrowerNumber:borrowersList)
                        borrowersListString+=borrowerNumber+" ";
                }
                borrowersListString+="\n";
                break;
            }
        }

        if (borrowersListString.equals(""))
            borrowersListString=queriedBookOrMovie+" does not belong to the library!";

        return borrowersListString;
    }
}
